local js_rihui = fk.CreateSkill {
  name = "js__rihui",
}

js_rihui:addEffect(fk.Damage, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and not data.chain and
      table.find(player.room:getOtherPlayers(player, false), function(p) return #p:getCardIds("j") > 0 end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#js__rihui-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if #p:getCardIds("j") > 0 and not p.dead then
        room:doIndicate(player.id, {p.id})
        p:drawCards(1, self.name)
      end
    end
  end,
})

js_rihui:addEffect(fk.TargetSpecified, {
  mute = true,
  main_skill = js_rihui,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill("js__rihui") and data.card and data.card.trueName == "slash" then
      local to = data.to
      return to:getMark("js__rihui-phase") == 0 and #to:getCardIds("j") == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:addCardUseHistory(data.card.trueName, -1)
    room:addPlayerMark(data.to, "js__rihui-phase", 1)
  end,
})


return js_rihui